package com.practice.backend.Repository;

import com.practice.backend.Entity.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface GoodsRepository extends JpaRepository<Goods, Integer>, JpaSpecificationExecutor<Goods> {

    Page<Goods> findByNameLike(String name, Pageable pageable);

    List<Goods> findByWareHouseId(Integer wareHouseId);
    @Query("select name from Goods where id = ?1")
    String finNameById(Integer id);

    //通过id查询质量
    @Query("select quality from Goods where id = ?1")
    Integer findQualityById(Integer id);

    @Query("select g from Goods g where g.name = ?1 and g.quality = ?2 and g.wareHouseId = ?3")
    Goods findByNameAndQualityAndWarehouse(String goodsName, Integer quality, Integer warehouse);
}
